var Member = require('../model/member');

module.exports.get = function (next) {
	var account  = this.query.account;
	var password = this.query.password;

	if (!account) {
		this.body = F.result(40001, '', 'Need Your Account');
		return;
	} else if (!password) {
		this.body = F.result(40002, '', 'Need Your Password');
		return;
	}

	Member.query('SELECT * FROM go_member WHERE username = "' + account + '"', function (err, result) {
		if (err) {
			this.body = F.result(err, '', result);
		} else {
			if (F.umd5(password) != result[0]['password']) {
				this.body = F.result(500, '', 'Password Error');
			} else {
				var sign = {
					uid : result[0]['id'],
					sign_time : parseInt(new Date().getTime() / 1000)
				}
				this.body = F.result(0, result);
			}
		}
	});
}